{{ define "admin/goods/index.html" }}
{{ template "admin/common/page_header.html" .}}


<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-toolbar d-flex flex-column flex-md-row">
                    <div class="toolbar-btn-action">
                        <a href="/admin/goods/add" class="btn btn-primary"><i class="mdi mdi-plus"></i>增加商品</a>
                    </div>

                    <form class="search-bar ml-md-auto" method="get" action="#!" role="form">
                        <input type="hidden" name="search_field" id="search-field" value="title">
                        <div class="input-group ml-md-auto">
                            <div class="input-group-prepend">
                                <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="search-btn">名称</button>
                                <div class="dropdown-menu" style="">
                                    <a class="dropdown-item" href="#!" data-field="title">名称</a>
                                    <a class="dropdown-item" href="#!" data-field="cat_name">栏目</a>
                                </div>
                            </div>
                            <input type="text" class="form-control" name="keyword" placeholder="请输入名称">
                        </div>
                    </form>
                </div>
                <div class="card-body">
                    <table class="table table-hover table-dark">
                        <thead>
                        <tr class="th">
                            <th>商品名称</th>
                            <th>价格</th>
                            <th>原价</th>
                            <th>点击量</th>
                            <th>上架</th>
                            <th>精品</th>
                            <th>新品</th>
                            <th>热销</th>
                            <th>排序</th>
                            <th>库存</th>
                            <th class="text-center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {{range $key,$value := .goodsList}}

                            <tr>
                                <td>{{$value.Title}}</td>
                                <td>{{$value.Price}}</td>
                                <td>{{$value.MarketPrice}}</td>
                                <td>{{$value.ClickCount}}</td>

                                <td class="text-center">
                                    {{if eq $value.Status 1}}
                                        <img class="chStatus" src="/static/admin/images/yes.gif" data-id="{{$value.Id}}" data-table="goods" data-field="status"/>
                                    {{else}}
                                        <img class="chStatus" src="/static/admin/images/no.gif" data-id="{{$value.Id}}" data-table="goods" data-field="status" />
                                    {{end}}
                                </td>

                                <td  class="text-center">
                                    {{if eq $value.IsBest 1}}
                                        <img class="chStatus" src="/static/admin/images/yes.gif" data-id="{{$value.Id}}" data-table="goods" data-field="is_best"/>
                                    {{else}}
                                        <img class="chStatus" src="/static/admin/images/no.gif" data-id="{{$value.Id}}" data-table="goods" data-field="is_best" />
                                    {{end}}
                                </td>

                                <td  class="text-center">
                                    {{if eq $value.IsNew 1}}
                                        <img class="chStatus" src="/static/admin/images/yes.gif" data-id="{{$value.Id}}" data-table="goods" data-field="is_new"/>
                                    {{else}}
                                        <img class="chStatus" src="/static/admin/images/no.gif" data-id="{{$value.Id}}" data-table="goods" data-field="is_new" />
                                    {{end}}
                                </td>

                                <td  class="text-center">
                                    {{if eq $value.IsHot 1}}
                                        <img class="chStatus" src="/static/admin/images/yes.gif" data-id="{{$value.Id}}" data-table="goods" data-field="is_hot"/>
                                    {{else}}
                                        <img class="chStatus" src="/static/admin/images/no.gif" data-id="{{$value.Id}}" data-table="goods" data-field="is_hot" />
                                    {{end}}
                                </td>

                                <td class="text-center">
                                    <span class="chSpanNum" data-id="{{$value.Id}}" data-table="goods" data-field="sort">{{$value.Sort}}</span>
                                </td>

                                <td class="text-center">
                                    <span class="chSpanNum" data-id="{{$value.Id}}" data-table="goods" data-field="goods_number">{{$value.GoodsNumber}}</span>
                                </td>

                                <td class="text-center">
                                    <a href="/admin/goods/edit?id={{$value.Id}}" />修改</a> 　
                                    <a class="delete" href="/admin/goods/delete?id={{$value.Id}}" />删除</a>
                                </td>
                            </tr>
                        {{end}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-lg-12">
            <div class="pagination justify-content-center" id="pagination"></div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/static/admin/js/jqPaginator.js"></script>
<script>

    $('#pagination').jqPaginator({
        totalPages: {{.totalPages}},
        visiblePages: 5,
        currentPage: {{.page}},
        onPageChange: function (num, type) {
            console.log(num, type);
            if(type!=='init'){
                location.href="/admin/goods?page="+num+"&keyword={{.keyword}}";
            }
        }
    });

</script>
{{end}}